( function() {
		Titanium.include(Ti.App.Properties.getString('base_folder_name') + 'foxbuddy.js');
		var win = Titanium.UI.currentWindow;
		var fuel_query_main_page_obj = null;
		function fuel_query_main_page() {
			var self = this;
			win.title = 'Fuel Query';
			var window_source = 'fuel_query_main_page';

			//public method
			/**
			 *  override init function of parent class: foxbuddy.js
			 */
			self.init = function() {
				try {
					self.init_auto_release_pool(win);
					self.data = [];
					self.init_navigation_bar('Query');
					self.init_vars();
					_init_city_field();
					self.init_table_view();
				} catch(err) {
					alert(err);
					//self.process_simple_error_message(err,window_source+' - self.init');
					return;
				}
			};

			/**
			 *  override table_view_click_event function of parent class: foxbuddy.js
			 */
			self.table_view_click_event = function(e) {
				try {
					_current_selected_row = e.row;
					var index = e.index;
					var filter_class = self.data[index].filter_class;
					switch(filter_class) {
						case 'select_city':
							_display_city_list_page(e);
							break;
					}
				} catch(err) {
					self.process_simple_error_message(err, window_source + ' - self.table_view_click_event');
					return;
				}
			};

			/**
			 *  update field value after set properties
			 *  in focus event call it
			 */
			self.update_field_value_after_set_properites = function() {
				try {
					if (Ti.App.Properties.getBool('update_unique_code_select_city_view_flag')) {
						_city_id = Ti.App.Properties.getString('update_unique_code_select_city_view_id');
						if (_current_selected_row != null) {
							_current_selected_row.city_id = _city_id;
							_current_selected_row.city_name = Ti.App.Properties.getString('update_unique_code_select_city_view_content');
							_current_selected_row.children[_current_selected_row.children.length - 1].text = _current_selected_row.city_name;
							if ((_current_selected_row.city_name === '') || (_current_selected_row.city_name === null)) {
								_current_selected_row.children[_current_selected_row.children.length - 1].visible = false;
								_current_selected_row.children[_current_selected_row.children.length - 2].visible = true;
							} else {
								_current_selected_row.children[_current_selected_row.children.length - 1].visible = true;
								_current_selected_row.children[_current_selected_row.children.length - 2].visible = false;
							}
						}
						_is_make_changed = true;
						Ti.App.Properties.setBool('update_unique_code_select_city_view_flag', false);
					}

				} catch(err) {
					self.process_simple_error_message(err, window_source + ' - self.update_field_value_after_set_properites');
					return;
				}
			};
			//private member
			var _city_id = 0;
			var _city_name = '';
			var _current_field_num = 0;
			var _current_selected_row = null;
			var _is_make_changed = false;
			var _selected_field_object = null;

			//private functions
			function _init_city_field() {
				try {
					var city_value = '';
					var is_required_field = true;
					_current_field_num++;
					var city_name_field = Ti.UI.createTableViewRow({
						city_id : _city_id,
						city_name : _city_name,
						className : 'select_city',
						filter_class : 'select_city',
						valueRequired : is_required_field, //for check value
						valuePosition : 3, //for check value
						valueType : 'text', //for check value,
						valuePrompt : 'Please select city.', //for check value
						height : self.default_table_view_row_height,
						hasChild : true
					});
					var city_label_field = Ti.UI.createLabel({
						text : 'City',
						color : self.font_color,
						font : {
							fontSize : self.font_size,
							fontWeight : self.font_weight
						},
						left : 10
					});
					city_name_field.add(city_label_field);
					var city_name_content_required_text_label = Ti.UI.createLabel({
						right : 10,
						height : self.default_table_view_row_height,
						width : self.set_a_field_width_in_table_view_row(city_label_field.text),
						textAlign : 'right',
						text : (is_required_field) ? 'Required' : 'Optional',
						opacity : self.hint_text_font_opacity,
						color : self.hint_text_font_color,
						font : {
							fontSize : self.normal_font_size
						}
					});
					city_name_field.add(city_name_content_required_text_label);
					var city_name_content_field = Ti.UI.createLabel({
						right : 10,
						height : ((_city_name === '') || (_city_name === null)) ? self.default_table_view_row_height : 'auto',
						width : self.set_a_field_width_in_table_view_row(city_label_field.text),
						textAlign : 'right',
						text : _city_name,
						color : self.selected_value_font_color,
						font : {
							fontSize : self.normal_font_size
						}
					});
					city_name_field.add(city_name_content_field);
					self.data.push(city_name_field);
					if ((_city_name === '') || (_city_name === null)) {
						city_name_content_field.visible = false;
					} else {
						city_name_content_required_text_label.visible = false;
					}
				} catch(err) {
					self.process_simple_error_message(err, window_source + ' - _init_city_field');
					return;
				}
			}

			function _display_city_list_page(e) {
				try {
					var city_win = Ti.UI.createWindow({
						url : self.get_file_path('url', 'base/select_unique_code_from_exist_list.js'),
						win_title : 'Select City',
						content_id_list : self.city_id_list, //table name
						content_name_list : self.city_name_list, //need to shwo field
						content : e.row.city_id,
						content_value : e.row.city_name,
						source : 'select_city'
					});
					Titanium.UI.currentTab.open(city_win, {
						animated : (self.is_ios_7_plus() && !self.set_animated_for_ios7) ? false : true
					});
				} catch(err) {
					self.process_simple_error_message(err, window_source + ' - _display_city_list_page');
					return;
				}
			}

		}


		win.addEventListener('focus', function() {
			try {
				if (fuel_query_main_page_obj == null) {
					var F = function() {
					};
					F.prototype = Foxbuddy.prototype;
					fuel_query_main_page.prototype = new F();
					fuel_query_main_page.prototype.constructor = fuel_query_main_page;
					fuel_query_main_page_obj = new fuel_query_main_page();
					//call init function of parent class -- foxbuddy.js
					fuel_query_main_page_obj.init();
				} else {
					fuel_query_main_page_obj.update_field_value_after_set_properites();
				}
			} catch(err) {
				alert(err);
				return;
			}
		});

		win.addEventListener('close', function() {
			try {
				fuel_query_main_page_obj.close_window();
				fuel_query_main_page_obj = null;
				win = null;
			} catch(err) {
				alert(err);
				return;
			}
		});
	}());
